import {Component, OnInit} from "@angular/core";
import {UserService} from "../../UserService";
import {LocalDataSource} from "ng2-smart-table";
import {UserInfo} from "../../energy/api/model/userInfo";
import {DevService} from "../../energy/api";
import {BaseRequest} from "../../utils/BaseRequest";

@Component({
  templateUrl: './user-dev.component.html'
})
export class UserDevComponent implements OnInit{
  user:UserInfo;
  settings = {
    pager: {
      display: false,
    },
    hideSubHeader: true,
    actions: {
      add: false,
      edit:false,
      delete: false,
      columnTitle: '操作',
      position: 'right',
    },
    columns: {
      devNo: {
        title: '编号',
        type: 'string',
      },
      devName: {
        title: '设备名称',
        type: 'string',
      },
      devType: {
        title: '设备类型',
        type: 'string',
      },
      createDate: {
        title: '创建日期',
        type: 'string',
      },
      enableDate: {
        title: '启用日期',
        type: 'string',
      },
      devStatus: {
        title: '设备状态',
        type: 'string',
      },
      runStatus: {
        title: '运行状态',
        type: 'string',
      },
      devAdmin: {
        title: '设备管理员',
        type: 'string',
      },
      devAdminPhoneNo: {
        title: '管理员联系电话',
        type: 'string',
      }
    },
  };
  maxPage:number = 1;
  page:number = 1;
  limit:number = 25;
  source: LocalDataSource = new LocalDataSource();
  constructor(private userService:UserService,private api:DevService){
    this.user = userService.getUser();
  }

  ngOnInit(): void {
    this.goto(this.page);
  }

  goto(page:number){
    this.page = page;
    this.api.postECAGetDeviceInfo(new BaseRequest({
        pageIndex:(this.page-1)*this.limit,
        pageSize:this.limit,
        unitId:this.user.unitId
      })
    ).toPromise().then(response=>{
      this.source.load(response.data.map(value => {
        return value;
      }));
    })
  }

}
